package com.wanshi.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanshi.mapper.RecordMapper;
import com.wanshi.po.Page;
import com.wanshi.po.Record;
import com.wanshi.po.RecordPo;
import com.wanshi.utils.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

@Service
public class RecordService {

    @Autowired
    private RecordMapper recordMapper;

    public void addRecord(Record record){
        recordMapper.addRecord(record);
    }

    public Page<RecordPo> list(int pagenum,int user_id){
        PageHelper.startPage(pagenum, Constants.PAGE_SIZE);
        List<RecordPo> list = recordMapper.list(user_id);
        PageInfo<RecordPo> pageInfo = new PageInfo<>(list);

        Page<RecordPo> page = new Page<>();
        page.setList(pageInfo.getList());
        page.setCurpage(pagenum);
        page.setCount( (int)pageInfo.getTotal());
        return page;
    }

    public Page<RecordPo> listByResult(Integer user_id, int result,int pagenum) {
        PageHelper.startPage(pagenum, Constants.PAGE_SIZE);
        List<RecordPo> list = recordMapper.listByResult(user_id,result);
        PageInfo<RecordPo> pageInfo = new PageInfo<>(list);

        Page<RecordPo> page = new Page<>();
        page.setList(pageInfo.getList());
        page.setCurpage(pagenum);
        page.setCount( (int)pageInfo.getTotal());
        return page;
    }

    public void delRecord(int user_id,int id) {
        recordMapper.delRecord(user_id,id);
    }

    public Page<RecordPo> findRecordByClsName(int pagenum,String clsname) {
        PageHelper.startPage(pagenum, Constants.PAGE_SIZE);
        List<RecordPo> list = recordMapper.findRecordByClsName(clsname);
        PageInfo<RecordPo> pageInfo = new PageInfo<>(list);

        Page<RecordPo> page = new Page<>();
        page.setList(pageInfo.getList());
        page.setCurpage(pagenum);
        page.setCount( (int)pageInfo.getTotal());
        return page;
    }

    public int getTotalDegreeAllTi(){
        return recordMapper.getTotalDegreeAllTi();
    }

    public int getTotalDegreeByUser(int user_id){
        return recordMapper.getTotalDegreeByUser(user_id);
    }

}
